/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-04-22
 * Time:7:49
 */
public class Demo8 {
    public static boolean isQuit = false;

    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while (!isQuit){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        //main线程等待5秒后，将标志位置为true，则t线程退出循环，任务执行结束，线程t终止
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isQuit = true;
        System.out.println("终止t线程！");
    }
}
